package com.ninthgroup.util;

import com.ninthgroup.entity.Permission;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：1452863884@qq.com rcg
 * @date ：Created in 2022/10/14 11:22
 * @description：权限工具类
 * @modified By：
 * @version:1.0
 */
public class PermissionUtil {


    public static List<Permission> firsts(List<Permission> permissions){
        //1.一级菜单
        List<Permission> firsts=new ArrayList<>();
        for (Permission permission:permissions){
            if(permission.getPid()==0){
                firsts.add(permission);
            }
        }

        //2.查询一级菜单下的二级菜单
        for(Permission first:firsts){
            List<Permission> children=new ArrayList<>();
            for(Permission p:permissions){
                if(first.getpId().equals(p.getPid())){
                    children.add(p);
                }
            }
            first.setChildren(children);
        }
        return firsts;
    }

}